package com.inossem.warehousestorage_inossem.activity.refund_storage;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.activity.base.BaseActivity;
import com.inossem.warehousestorage_inossem.activity.out_storage.extra.OutStorageExtra;
import com.inossem.warehousestorage_inossem.activity.refund_storage.extra.RefundStorageExtra;
import com.inossem.warehousestorage_inossem.utils.ActivityUtils;
import com.zhy.android.percent.support.PercentRelativeLayout;

public class RefundStorageResultActivity extends BaseActivity {

    private TextView title, message, result;

    private Button nextStep, back;

    private String mMessage, mConfirmMessage;

    @Override
    protected void onCreateImpl(Bundle savedInstanceState) {
        setContentView(R.layout.activity_refund_storage_result);
        initView(RefundStorageResultActivity.this);
    }

    @Override
    protected void onResumeImpl() {
        initData(RefundStorageResultActivity.this);
    }

    private void initView(Activity activity) {
        title = (TextView) activity.findViewById(R.id.headerTitle);
        message = (TextView) activity.findViewById(R.id.message);
        result = (TextView) activity.findViewById(R.id.result);
        nextStep = (Button) activity.findViewById(R.id.nextStep);
        back = (Button) activity.findViewById(R.id.back);
    }

    private void initData(Activity activity) {
        title.setText(getResources().getString(R.string.activity_emergency_warehousing_result_title));
        nextStep.setText(getResources().getString(R.string.activity_refund_storage_result_the_subsequent_process_of_the_withdrawal));
        PercentRelativeLayout leftTitleLayout = ActivityUtils.initBackAndFunction(activity, R.string.activity_receive_receive_item_title_short, new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                finish();
            }
        });
        leftTitleLayout.setVisibility(View.INVISIBLE);
        nextStep.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                goReceiveManageActivity(activity, true);
            }
        });
        nextStep.setVisibility(View.GONE);
        back.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                goReceiveManageActivity(activity, false);
            }
        });
        getExtra(activity);
        getData(activity);
    }

    private void getExtra(Activity activity) {
        mMessage = activity.getIntent().getStringExtra(OutStorageExtra.MESSAGE);
        mConfirmMessage = activity.getIntent().getStringExtra(OutStorageExtra.CONFIRM_MESSAGE);
    }

    private void getData(Context context) {
        message.setText(mMessage);
        result.setText(context.getResources().getString(R.string.activity_receive_result_confirm_success));
    }

    private void goReceiveManageActivity(Activity activity, boolean flag) {
        Intent intent = new Intent(activity, RefundStorageManageActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(RefundStorageExtra.FLAG, flag);
        activity.startActivity(intent);
        activity.finish();
    }

    @Override
    public void onBackPressed() {

    }
}
